//
//  YTRightBackView.m
//  YUNT
//
//  Created by 小萌 on 2017/11/12.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTRightBackView.h"
#import "YTCamerSetViewController.h"
#import "YTCouldViewController.h"

@interface YTRightBackView ()
@property (nonatomic,strong) UIWindow *rightWindow;
@property (nonatomic, strong) YTNavigationController *tempNavi;
@end

@implementation YTRightBackView
#pragma mark - LifeCycle
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
    
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    if([UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationPortrait||[UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationPortraitUpsideDown){
        self.tempNavi.view.frame = CGRectMake(0,self.originY, ScreenWidth, 300);
    }else{
        self.tempNavi.view.frame = CGRectMake(self.width - 300, 0, 300, ScreenHeight);
    }
    
}
#pragma mark -setter&getter
- (void)setIndex:(NSInteger)index
{
    if (_index!= index) {
        _index = index;
    }
    self.hidden = NO;
    if (self.tempNavi) {
        [self.tempNavi removeFromParentViewController];
        [self.tempNavi.view removeFromSuperview];
        self.tempNavi = nil;
    }
    if(index == 0){
        NSLog(@"首页");
    }else if (index == 1){
        NSLog(@"相机");
        YTCamerSetViewController *camerSet = [[YTCamerSetViewController alloc] init];
        YTNavigationController *camerNavi = [[YTNavigationController alloc] initWithRootViewController:camerSet];
        [self.previewVC.view insertSubview:camerNavi.view aboveSubview:self];
        [self.previewVC addChildViewController:camerNavi];
        self.tempNavi = camerNavi;
    }else if (index == 2){
        NSLog(@"云台");
        YTCouldViewController *couldVC = [[YTCouldViewController alloc] init];
        YTNavigationController *couldNavi = [[YTNavigationController alloc] initWithRootViewController:couldVC];
        [self.previewVC.view insertSubview:couldNavi.view aboveSubview:self];
        [self.previewVC addChildViewController:couldNavi];
        self.tempNavi = couldNavi;
    }else if (index == 3){
        NSLog(@"设置");
    }else if (index == 4){
        NSLog(@"闪光灯");
    }
    [self setNeedsLayout];
}
#pragma mark - private

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"");
    [UIView animateWithDuration:0.3 animations:^{
        if([UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationPortrait||[UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationPortraitUpsideDown){
            self.tempNavi.view.frame = CGRectMake(0, -300, ScreenWidth, 300);
        }else{
            self.tempNavi.view.frame = CGRectMake(self.width, 0, 300, ScreenHeight);
        }
        
    } completion:^(BOOL finished) {
        self.hidden = YES;
        [self.tempNavi removeFromParentViewController];
        [self.tempNavi.view removeFromSuperview];
        self.tempNavi = nil;
        BlockCallWithOneArg(self.completion, nil);
    }];
}
@end
